package com.jinhua.mybatis.mapper;




import com.jinhua.mybatis.handler.MybatisAnnotationHandler;
import com.jinhua.mybatis.util.BaseSqlHelper;
import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import java.util.List;
import java.util.Map;

/**
 * mybatis的通用mapper
 */
@CacheNamespace
public interface MybatisBaseMapper {

	String LIST_PARAM = "list";

	@SelectProvider(type = MybatisAnnotationHandler.class, method = "selectOne")
	@Options(useCache = false)
	Map selectOne(BaseSqlHelper baseSqlHelper);

	@SelectProvider(type = MybatisAnnotationHandler.class, method = "selectOneByCache")
	Map selectOneByCache(BaseSqlHelper baseSqlHelper);


	@SelectProvider(type = MybatisAnnotationHandler.class, method = "selectAll")
	@Options(useCache = false)
	List<Map> selectAll(BaseSqlHelper baseSqlHelper);

	@SelectProvider(type = MybatisAnnotationHandler.class, method = "selectAllByCache")
	List<Map> selectAllByCache(BaseSqlHelper baseSqlHelper);

	@UpdateProvider(type = MybatisAnnotationHandler.class, method = "update")
	int update(BaseSqlHelper baseSqlHelper);


	@InsertProvider(type = MybatisAnnotationHandler.class, method = "save")
	@Options(useGeneratedKeys = true,keyProperty = "id")
	int save(@Param(LIST_PARAM) List<BaseSqlHelper> baseSqlHelpers);

	@DeleteProvider(type = MybatisAnnotationHandler.class, method = "delete")
	int delete(BaseSqlHelper baseSqlHelper);

}
